package com.sample.livewallpaperdemo;

import android.content.Context;
import android.graphics.Color;
import android.view.MotionEvent;
import android.view.animation.BounceInterpolator;

import org.rajawali3d.Object3D;
import org.rajawali3d.animation.Animation3D;
import org.rajawali3d.animation.RotateAnimation3D;
import org.rajawali3d.materials.Material;
import org.rajawali3d.materials.textures.ATexture;
import org.rajawali3d.materials.textures.Texture;
import org.rajawali3d.math.vector.Vector3;
import org.rajawali3d.primitives.Sphere;
import org.rajawali3d.renderer.Renderer;

/**
 * Created by jtxiang on 17-7-5.
 */

public class TestRenderer extends Renderer {

    private Object3D mSphere;

    public TestRenderer(Context context) {
        super(context);
    }

    @Override
    protected void initScene() {
        try {
            getCurrentScene().setBackgroundColor(Color.BLUE);

            Material material = new Material();
            Texture texture = new Texture("earthColors", R.drawable.earthtruecolor_nasa_big);
            material.addTexture(texture);
            material.setColorInfluence(0);
            mSphere = new Sphere(1, 24, 24);
            mSphere.setMaterial(material);
            getCurrentScene().addChild(mSphere);
        } catch (ATexture.TextureException e) {
            e.printStackTrace();
        }

        getCurrentCamera().enableLookAt();
        getCurrentCamera().setLookAt(0, 0, 0);
        getCurrentCamera().setZ(6);
        getCurrentCamera().setOrientation(getCurrentCamera().getOrientation().inverse());

        // 动画
        Animation3D anim = new RotateAnimation3D(new Vector3(90, 180, 270));
        anim.setDurationMilliseconds(2000);
        anim.setTransformable3D(mSphere);
        anim.setRepeatCount(1000000);
        anim.setRepeatMode(Animation3D.RepeatMode.REVERSE);
        anim.setInterpolator(new BounceInterpolator());
        getCurrentScene().registerAnimation(anim);
        anim.play();
    }

    @Override
    public void onRender(final long elapsedTime, final double deltaTime) {
        super.onRender(elapsedTime, deltaTime);
        //mSphere.rotate(Vector3.Axis.Y, 1.0);
    }

    public void onTouchEvent(MotionEvent event){
    }

    public void onOffsetsChanged(float x, float y, float z, float w, int i, int j){
    }
}
